*******************************************************************
*Replication code for
*	Article: How COVID-19 affects voting for incumbents: evidence from local elections in France
*	Journal: PlosOne
*	Authors: Davide Morisi, Héloïse Cloléry, Guillaume Kon Kam King, and Max Schaub
*******************************************************************

*ANALYSIS
*This file replicates all the tables and figures included in the main text and in the supplementary information
*apart from the analysis of the parallel trend assumption


*open dataset
use "$pathdata\main_dataset_recoded.dta", clear

*Covariates
global controls_log_full log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5 log_baseline_mortality Turnout2014 N_candidates_2020_1st

*Department fixed effects
encode DepartmentCode, gen(dp)

*Remove cities that changed between 2014 and 2020
* Because we only have data for municips over 1,000 inhabitants, our sample
* changes between 2014 because some municips join this group, while others drop out, see:
fre comment_ElectoralData
* our effective sample with full information is given by:
keep if comment_ElectoralData=="" // 999 observations deleted

*Exclude Paris, Marseille and Lyon with different electoral system
fre MunicipalityName if DepartmentCode=="75" // Paris, 17 obs
fre MunicipalityName if DepartmentCode=="13" & MunicipalityCode=="055SR01" // Marseille, 1 obs
fre MunicipalityName if DepartmentCode=="69" & MunicipalityCode=="123SR01" // Lyon, 1 obs
gen pml = 0 
replace pml = 1 if (DepartmentCode=="75") | (DepartmentCode=="13" & MunicipalityCode=="055SR01") | (DepartmentCode=="69" & MunicipalityCode=="123SR01")
label de pml 1 "Paris, Marseille, Lyon"
label val pml pml
fre pml
drop if pml==1 // dropped 19 observations

*quantiles of prevalence
*main specification
xtile prevalence1_100_dec_full = prevalence1_100, nq(10)
xtile prevalence1_100_dec = prevalence1_100 if Incumbents_sample==1, nq(10)
gen prevalence1_100_dec01 = (prevalence1_100_dec-1)/9
xtile prevalence1_100_quin = prevalence1_100 if Incumbents_sample==1, nq(5)
xtile prevalence1_100_quart_full = prevalence1_100, nq(4)
xtile prevalence1_100_quar = prevalence1_100 if Incumbents_sample==1, nq(4)
xtile prevalence1_100_dum = prevalence1_100 if Incumbents_sample==1, nq(2)
*4 weeks
xtile prevalence4w_100_dec = prevalence_4w_1st_rnd_100 if Incumbents_sample==1, nq(10)
gen prevalence4w_100_dec01 = (prevalence4w_100_dec-1)/9
xtile prevalence4w_100_quin = prevalence_4w_1st_rnd_100 if Incumbents_sample==1, nq(5)
xtile prevalence4w_100_quar = prevalence_4w_1st_rnd_100 if Incumbents_sample==1, nq(4)
xtile prevalence4w_100_dum = prevalence_4w_1st_rnd_100 if Incumbents_sample==1, nq(2)

*standardized dv
egen stvote_share_Incumbent_2020 = std(vote_share_Incumbent_2020)
sum vote_share_Incumbent_2020 stvote_share_Incumbent_2020

global PathRES = "tables\"

*******************

*
*Table S1. Balance statistics
fre Incumbents_sample
eststo clear
eststo: logit Incumbents_sample c.prevalence1_100_dec_full $controls_log_full i.dp
esttab using "${PathRES}TableS1.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S1. Predictors of being a city with an incumbent") wide compress noeqlines replace


*
*Table S2. Summary statistics - incumbent sample only
eststo clear
estpost sum vote_share_Incumbent_2020 vote_share_Incumbent_2014 ///
prevalence1 lprevalence1_norm ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 ///
log_education2 log_education5 log_baseline_mortality Turnout2014 N_candidates_2020_1st if Incumbents_sample==1
esttab using "${PathRES}TableS2.tex", title("Table S2. Summary statistics") cells("count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") replace

*
*Table S3. Political affiliations of incumbents
ta IncumbentList if Incumbents_sample==1 // the affiliation of the incumbents in 2020


*
*Table S4. Effects of COVID-19 on voting for incumbents (MAIN MODELS)
eststo clear
*deciles
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*areg stvote_share_Incumbent_2020 c.prevalence1_100_dec01 $controls_log_full vote_share_Incumbent_2014, absorb(dp) // effect on standardized DV
*quartiles
eststo: areg vote_share_Incumbent_2020 i.prevalence1_100_quar $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*areg vote_share_Incumbent_2020 ib2.prevalence1_100_quar $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*logged
eststo: areg vote_share_Incumbent_2020 c.lprevalence1_norm $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*quintiles
eststo: areg vote_share_Incumbent_2020 i.prevalence1_100_quin $controls_log_full vote_share_Incumbent_2014, absorb(dp)
esttab using "${PathRES}TableS4.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S4. Effects of Covid-19 on voting for incumbents") compress noeqlines replace


*****
*Figure 1

*Plot A - deciles
*continuous predictor
areg vote_share_Incumbent_2020 c.prevalence1_100_dec $controls_log_full vote_share_Incumbent_2014, absorb(dp) // b=0.271
margins, at(prevalence1_100_dec=(1(1)10)) post // 71.49 - 73.93
*categorical predictor
areg vote_share_Incumbent_2020 i.prevalence1_100_dec $controls_log_full vote_share_Incumbent_2014, absorb(dp)
margins, at(prevalence1_100_dec=(1(1)10)) post
coefplot, vert name(fig1A, replace) graphregion(color(white)) recast(connected) ///
yscale(range(70(1)76)) ylabel(70(1)76) ///
xscale(range(1(1)10)) xlabel(1(1)10) ///
ytitle("Predicted vote for incumbents in 2020") ///
title("A) Deciles") xtitle("Spread of Covid-19 (deciles)")
addplot fig1A: (function y=71.214+(0.2722*x), range(1 10) lpattern(dash) lcolor(gs2))
graph save "fig1A" "$pathfigures\PlosOne_Fig1_plotA.gph"

*Plot B - quartiles
areg vote_share_Incumbent_2020 i.prevalence1_100_quar $controls_log_full vote_share_Incumbent_2014, absorb(dp)
margins, at(prevalence1_100_quar=(1(1)4)) post
coefplot, vert name(fig1B, replace) graphregion(color(white)) recast(connected) ///
yscale(range(70(1)76)) ylabel(70(1)76) ///
xscale(range(1(1)4)) xlabel(1(1)4) ///
ytitle("") ///
title("B) Quartiles") xtitle("Spread of Covid-19 (quartiles)")
graph save "fig1B" "$pathfigures\PlosOne_Fig1_plotB.gph"

*combined figure
graph combine "$pathfigures\PlosOne_Fig1_plotA.gph" ///
"$pathfigures\PlosOne_Fig1_plotB.gph", graphregion(color(white)) ycommon
graph save "Graph" "$pathfigures\PlosOne_Fig1.gph"



****
*Table S5. Additional models adding controls gradually
eststo clear
*1
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec log_baseline_mortality, absorb(dp)
*2
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5, absorb(dp)
*3
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5 Turnout2014 N_candidates_2020_1st, absorb(dp)
*4 number of candidates categorical
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5  Turnout2014 i.N_candidates_3cat vote_share_Incumbent_2014, absorb(dp)
*5 no DP
eststo: reg vote_share_Incumbent_2020 c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5 Turnout2014 N_candidates_2020_1st vote_share_Incumbent_2014
esttab using "${PathRES}TableS5.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S5. Additional models introducing covariates gradually") compress noeqlines replace


*
*Table A6. First difference
eststo clear
*1
eststo: areg inc_vote_gap c.prevalence1_100_dec log_baseline_mortality, absorb(dp)
*2
eststo: areg inc_vote_gap c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5, absorb(dp)
*3
eststo: areg inc_vote_gap c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5 Turnout2014 N_candidates_2020_1st, absorb(dp)
*4
eststo: reg inc_vote_gap c.prevalence1_100_dec log_baseline_mortality ///
log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_education2 log_education5 Turnout2014 N_candidates_2020_1st
esttab using "${PathRES}TableS6.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S6. First-difference regression models") compress noeqlines replace


*
*Table S7. Effects of Covid-19 on voting for incumbents - (alternative specification of COVID-19 spread)
eststo clear
*deciles
eststo: areg vote_share_Incumbent_2020 c.prevalence4w_100_dec $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*quartiles
eststo: areg vote_share_Incumbent_2020 i.prevalence4w_100_quar $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*logged
eststo: areg vote_share_Incumbent_2020 c.lprevalence4w_norm $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*quintiles
eststo: areg vote_share_Incumbent_2020 i.prevalence4w_100_quin $controls_log_full vote_share_Incumbent_2014, absorb(dp)
esttab using "${PathRES}TableS7.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S7. Effects of Covid-19 on voting for incumbents (alternative specification of COVID-19 spread)") compress noeqlines replace


*
*Table S8. Interactions with political affiliation
fre incumbent3cat
eststo clear
*1. deciles
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) // r.c. = left
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec##ib2.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) // r.c. = centre
*2. quartiles
eststo: areg vote_share_Incumbent_2020 i.prevalence1_100_quar##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) // r.c. = left
eststo: areg vote_share_Incumbent_2020 i.prevalence1_100_quar##ib2.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) // r.c. = centre
esttab using "${PathRES}TableS8.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S8. Interactions with political affiliation") compress noeqlines replace


****
*Figure 2. Effects of Covid-19 on voting for incumbents by political affiliation
fre incumbent3cat

*A) deciles - Model 1 in Table S8
eststo clear
areg vote_share_Incumbent_2020 c.prevalence1_100_dec##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) 
eststo left: margins, at(incumbent3cat==1 prevalence1_100_dec=(1(1)10)) post // left
areg vote_share_Incumbent_2020 c.prevalence1_100_dec##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) 
eststo centre: margins, at(incumbent3cat==2 prevalence1_100_dec=(1(1)10)) post // centre
areg vote_share_Incumbent_2020 c.prevalence1_100_dec##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp) 
eststo right: margins, at(incumbent3cat==3 prevalence1_100_dec=(1(1)10)) post // right
*graph
coefplot left centre right, vert name(fig2A, replace) graphregion(color(white)) recast(connected) ///
xscale(range(1(1)10)) xlabel(1(1)10) legend(off) level(90 95) ///
title("A) Deciles") ytitle("Predicted vote for incumbents in 2020") xtitle("Spread of Covid-19 (deciles, linear predictor)")

*B) quartiles - model 2 in table S8
eststo clear
areg vote_share_Incumbent_2020 i.prevalence1_100_quar##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp)
eststo left: margins, at(incumbent3cat==1 prevalence1_100_quar=(1(1)4)) post
areg vote_share_Incumbent_2020 i.prevalence1_100_quar##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp)
eststo centre: margins, at(incumbent3cat==2 prevalence1_100_quar=(1(1)4)) post
areg vote_share_Incumbent_2020 i.prevalence1_100_quar##i.incumbent3cat $controls_log_full vote_share_Incumbent_2014, absorb(dp)
eststo right: margins, at(incumbent3cat==3 prevalence1_100_quar=(1(1)4)) post
*graph
coefplot left centre right, vert name(fig2B, replace) graphregion(color(white)) recast(connected) ///
xscale(range(1(1)4)) xlabel(1(1)4) level(90 95) ///
title("B) Quartiles") ytitle("") xtitle("Spread of Covid-19 (quartiles)")

*combined figure
graph combine fig2A fig2B, graphregion(color(white)) ycommon
graph save "Graph" "$pathfigures\PlosOne_Fig2.gph"



************************
*Propensity score matching

* Matching
* Dichotimize the treatment variable to use propensity-score matching
cap drop hazard_ratebin
recode prevalence1_100_quar (1/2 = 0) (3/4=1), gen(hazard_ratebin)
* Manually calculate propensity score (for greater control); include pre-treatment demographics that predict the 'treatment', i.e. having high numbers of excess mortality
cap drop pscore 
probit hazard_ratebin $controls_log_full vote_share_Incumbent_2014 i.dp, asis
predict pscore
* Conduct 1:1 matching on the propensity score, using the score just calculated and psmatch2 and a (punishing) caliper of 0.025
psmatch2 hazard_ratebin, pscore(pscore) neighbor(1) noreplacement caliper(.025)
* very good balance
orth_out $controls_log_full vote_share_Incumbent_2014 if _weight==1, by(hazard_ratebin) pcompare

* Table S9. Propensity score matching
eststo clear
eststo: areg vote_share_Incumbent_2020 prevalence1_100_dec $controls_log_full vote_share_Incumbent_2014 if _weight==1, absorb(dp)
eststo: areg vote_share_Incumbent_2020 i.prevalence1_100_quar $controls_log_full vote_share_Incumbent_2014 if _weight==1, absorb(dp)
esttab using "${PathRES}TableS9.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S9. Propensity score matching") compress noeqlines replace


******
*PLACEBO TEST

global controls_placebo log_PopDensity log_MaleToFemaleRatio log_shareImmigrants log_shareBlueCollar log_shareUnemp log_shareAbove65 MedianStandardLiving100 log_baseline_mortality log_education2 log_education5

*note: very few observations because change of electoral rules (above 3500 inhabitants)
sum vs_2008incumbent_2014 // Share of votes obtained by the 2014 incumbent candidate in 2014 1st round
sum vote_share_incumbent_2008 // Share of votes obtained by the 2014 incumbent in 2008 1st round

*Table A10. Effect of covid-19 on voting for incumbents in 2014 (controlling for votes in 2008)
eststo clear
*deciles
eststo: areg vs_2008incumbent_2014 prevalence1_100_dec_full $controls_placebo vote_share_incumbent_2008, absorb(dp)
*quartiles
eststo: areg vs_2008incumbent_2014 i.prevalence1_100_quart_full $controls_placebo vote_share_incumbent_2008, absorb(dp)
esttab using "${PathRES}TableS10.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S10. Placebo tests: Effect of COVID-19 on voting for incumbents in 2014") compress noeqlines replace


************
*MECHANISMS

*Table S14. Mechanisms
eststo clear
*emotions
gen emotion_anx_worried01 = emotion_anx_worried/2 // rescaled from 0 to 1
*control also for rural/urban area
recode size (10=1 "<2000 inhabitants") (20=2 "<20,000 inhabitants") (30 40=3 "20,000 or above"), gen(rural_urban)
label var rural_urban "Municipalities by population size"
fre rural_urban
*anxiety
eststo: reg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.emotion_anx_worried01 $controls_log_full vote_share_Incumbent_2014 i.rural_urban, cluster(dep_size_code)
*change in median household income
sum income_change100, d // change in hundreds of euros
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.income_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
* change in unemployment
sum unempl_change100, d // positive = unemployment went up in 2017 relative to 2014
eststo: areg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.unempl_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
esttab using "${PathRES}TableS14.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S14. Testing mechanisms") compress noeqlines replace


***********
*Figure 3
*anxiety
reg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.emotion_anx_worried01 $controls_log_full vote_share_Incumbent_2014 i.rural_urban, cluster(dep_size_code)
margins, dydx(prevalence1_100_dec) at(emotion_anx_worried01=(0(.25)1)) post
coefplot, vert name(fig3A, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"0" 2"0.25" 3"0.5" 4"0.75" 5"1")  level(90 95) ///
title("a) ...levels of anxiety") ytitle("Effect of COVID-19 on vote for incumbents") xtitle("Self-reported level of anxiety""from 0 (min) to 1(max)")

*income change
sum income_change100 if vote_share_Incumbent_2020!=., d
areg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.income_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
margins, dydx(prevalence1_100_dec) at(income_change100=(0.18(3.7)14.98)) post // display from 5th to 95th pctile of income change
coefplot, vert name(fig3B, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"0.2" 2"3.9" 3"7.6" 4"11.3" 5"15.0")  level(90 95) ///
title("b) ...change in median household income") ytitle("") xtitle("Change in median income between 2014 and 2017""(hundreds of euros), from 5th to 95th percentile")

*change in unemployment
sum unempl_change100 if vote_share_Incumbent_2020!=., d
areg vote_share_Incumbent_2020 c.prevalence1_100_dec##c.unempl_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
*margins, dydx(prevalence1_100_dec) at(unempl_change100=(1.59(2.253)10.61)) post
margins, dydx(prevalence1_100_dec) at(unempl_change100=(1(2.5)11)) post
coefplot, vert name(fig3C, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"1%" 2"3.5%" 3"6%" 4"8.5%" 5"11%") level(90 95) ///
title("c) ...change in unemployment rate") ytitle("") xtitle("Change in unemployment rate between 2014""and 2017 (from approx. 5th to 95 percentile)")

*combined
graph combine fig3A fig3B fig3C, graphregion(color(white)) ycommon title("Effects of Covid-19 spread by...")
graph save "Graph" "$pathfigures\PlosOne_Fig3.gph"


***********
*Fig S1 - Alternative figure 3 using quartiles of prevalence
*anxiety
reg vote_share_Incumbent_2020 i.prevalence1_100_quar##c.emotion_anx_worried01 $controls_log_full vote_share_Incumbent_2014 i.rural_urban, cluster(dep_size_code)
margins, dydx(4.prevalence1_100_quar) at(emotion_anx_worried01=(0(.25)1)) post
coefplot, vert name(fig3AA, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"0" 2"0.25" 3"0.5" 4"0.75" 5"1")  level(90 95) ///
title("a) ...levels of anxiety") ytitle("Effect of COVID-19 on vote for incumbents") xtitle("Self-reported level of anxiety""from 0 (min) to 1(max)")

*income change
sum income_change100 if vote_share_Incumbent_2020!=., d
areg vote_share_Incumbent_2020 i.prevalence1_100_quar##c.income_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
margins, dydx(4.prevalence1_100_quar) at(income_change100=(0.18(3.7)14.98)) post // display from 5th to 95th pctile of income change
coefplot, vert name(fig3BB, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"0.2" 2"3.9" 3"7.6" 4"11.3" 5"15.0")  level(90 95) ///
title("b) ...change in median household income") ytitle("") xtitle("Change in median income between 2014 and 2017""(hundreds of euros), from 5th to 95th percentile")

*change in unemployment
sum unempl_change100 if vote_share_Incumbent_2020!=., d
areg vote_share_Incumbent_2020 i.prevalence1_100_quar##c.unempl_change100 $controls_log_full vote_share_Incumbent_2014, absorb(dp)
margins, dydx(4.prevalence1_100_quar) at(unempl_change100=(1(2.5)11)) post
coefplot, vert name(fig3CC, replace) graphregion(color(white)) ///
yline(0, lcolor(gs10) lpattern(dash)) ///
xscale(range(1(1)5)) xlabel(1"1%" 2"3.5%" 3"6%" 4"8.5%" 5"11%") level(90 95) ///
title("c) ...change in unemployment rate") ytitle("") xtitle("Change in unemployment rate between 2014""and 2017 (from approx. 5th to 95 percentile)")

*combined
graph combine fig3AA fig3BB fig3CC, graphregion(color(white)) ycommon title("Effects of Covid-19 spread by...") note("Note: Effect of 4th quartile of Covid-19 prevalence vs. 1st quartile")
graph save "Graph" "$pathfigures\PlosOne_FigS1.gph"


**********
*Diff-in-diff 

* binary Covid treatment indicator
recode prevalence1_100_quar (1/2 = 0) (3/4=1), gen(treat) // same as for matching

*simple t-test
gen vote_change = vote_share_Incumbent_2020-vote_share_Incumbent_2014
ttest vote_change, by(treat) unequal
*diff = 1.81, p<0.05

* renaming
rename vote_share_Incumbent_2020 vote_share_Incumbent2020
rename vote_share_Incumbent_2014 vote_share_Incumbent2014
rename log_shareImmigrants log_shareImmigrants2020
rename log_shareBlueCollar log_shareBlueCollar2020
rename log_shareUnemp log_shareUnemp2020  
rename MedianStandardLiving MedianStandardLiving2020
gen log_shareImmigrants2014 = log(shareImmigrants2014)
gen log_shareBlueCollar2014 = log(shareBlueCollar2014)	
gen log_shareUnemp2014 = log(shareUnemp2014)	

* transform to long
keep municip vote_share_Incumbent2020 vote_share_Incumbent2014 treat log_shareImmigrants* log_shareBlueCollar* log_shareUnemp* MedianStandardLiving*
encode municip, gen(municipen)
drop if municipen==.
reshape long vote_share_Incumbent log_shareImmigrants log_shareBlueCollar log_shareUnemp MedianStandardLiving, i(municip) j(year)
recode year (2014 = 0) (2020 = 1), gen(post)
label variable treat "Treated"
label define treat 0 "Control" 1 "Treated"
label values treat treat
label variable post "Election"
label define post 0 "2014" 1 "2020"
label values post post
global controls_did log_shareImmigrants log_shareBlueCollar log_shareUnemp MedianStandardLiving

* Table S11 'Manual' DiD
bys treat post: sum vote_share_Incumbent
version 16: eststo didtab: table treat post, c(mean vote_share_Incumbent) format(%9.2f)
di (72.23 - 68.46) - (73.19 - 67.62) // 1.80
/*
\begin{table}[]
\begin{tabular}{llll}
                 & \multicolumn{2}{l}{Election} & Diff \\ \hline
Treatment status & 2014          & 2020         &      \\ \hline
Control          & 68.46         & 72.23        & 3.77 \\
Treated          & 67.62         & 73.19        & 5.57 \\ \hline
Diff             & -0.84         & 0.96         & 1.80 \\ \hline
\end{tabular}
\end{table}
*/

*
*Table S2. DiD in regression framework
* Simple model (same coefficient as above, SEs bootstrapped as per Bertrand, Duflo, and Mullainathan 2004)
eststo did_naive: bootstrap, cluster(municip) seed(7) reps(1000) nodots: reg vote_share_Incumbent c.treat##c.post 
* Model including controls
eststo did_controls: bootstrap, cluster(municip) seed(7) reps(1000) nodots: reg vote_share_Incumbent c.treat##c.post $controls_did

esttab did_naive did_controls using "${PathRES}TableS12.tex", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Table S12. Diff-in-diff") compress noeqlines replace






